package pokpok.domaine;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable
public class Joueur implements Identifiable {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key id;

	@Persistent
	private String nom;
	@Persistent
	private String prenom;
	@Persistent
	private String pseudo;

	public Joueur(Key id, String nom, String prenom, String pseudo) {
		super();
		this.id = id;
		this.nom = nom;
		this.prenom = prenom;
		this.pseudo = pseudo;
	}

	public Joueur(String nom, String prenom, String pseudo) {
		super();
		this.nom = nom;
		this.prenom = prenom;
		this.pseudo = pseudo;
	}

	public Key getId() {
		return id;
	}

	public String getNom() {
		return nom;
	}

	public String getPrenom() {
		return prenom;
	}

	public String getPseudo() {
		return pseudo;
	}

	public String getStringKey() {
		return KeyFactory.keyToString(id);
	}

	public String getLibelle() {
		String retour = "";
		String pseudoLib = pseudo == null ? "" : pseudo;
		String nomLib = nom == null ? "" : nom;
		String prenomLib = prenom == null ? "" : prenom;
		if (!"".equals(pseudoLib)) {
			retour = retour + pseudoLib;
			if (!"".equals(prenomLib) || !"".equals(nomLib)) {
				retour = retour + " (" + prenomLib + " " + nomLib + ")";
			}
			return retour;
		} else {
			retour = retour + prenomLib + " " + nomLib;
			return retour;
		}
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public void setPseudo(String pseudo) {
		this.pseudo = pseudo;
	}

	public String getIdString() {
		return KeyFactory.keyToString(id);
	}
}
